﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonsLib.Utility;
using System.Data.SqlClient;
using MaxLeaf.Platform.Functions;
using System.Data.Common;
using MaxLeaf.Platform.Commons;
using MaxLeaf.Platform.DataContract;
using CommonsLib.DB;
using System.Data;

namespace MaxLeaf.Platform.DALImplementation
{
    public class imStoresReqDtlDAL : BaseDAL
    {
        protected override KeyValuePair<string, IDataParameter[]> GetCond(DBAccess dbcon, object model, List<Cond> lstCond)
        {
            KeyValuePair<string, IDataParameter[]> kvp=base.GetCond(dbcon,   model, lstCond);

            string strCond = kvp.Key;
            List<IDataParameter> lstParam =new List<IDataParameter>( kvp.Value);
            foreach (Cond cond in lstCond)
            {
                if (cond.PropName.Equals("Func_GroupFInterID"))
                {
                    if (!string.IsNullOrEmpty(strCond))
                    {
                        strCond += " and ";
                    }
                    strCond += "  exists (select h.GroupFInterID  from imStoresReqHdr h where h.finterid=hdrid  and h.GroupFInterID=@GroupFInterID) ";
                    lstParam.Add(new SqlParameter("@GroupFInterID", cond.Value));
                    break;
                }
                
            }

            return new KeyValuePair<string, IDataParameter[]>(strCond, lstParam.ToArray());
        }

        public void SetUsingListId(DBAccess dbcon, int intKey, int intUsingListId)
        {
            string strSql = "update imStoresReqDtl set UsingListId=@UsingListId where DtlID=@FInterID  ";
            dbcon.ExecuteSql(strSql, new SqlParameter[] { new SqlParameter("@FInterID", intKey.ToString())
                ,new SqlParameter("@UsingListId", intUsingListId.ToString())
            });
        }
    }
}
